package com.atgm.mall.gmmallcart.controller;

import com.atgm.common.utils.R;
import com.atgm.mall.gmmallcart.Service.GameShoppingService;
import com.atgm.mall.gmmallcart.vo.req.CartRemoveReqVo;
import com.atgm.mall.gmmallcart.vo.req.GameCartReqVo;
import com.atgm.mall.gmmallcart.vo.req.MemberWishReqVo;
import com.atgm.mall.gmmallcart.vo.resp.GameCartRespVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("gmmallcart/gameshopping")
public class GameShoppingController {

    @Autowired
    private GameShoppingService gameShoppingService;

    /**
     * 获取用户的购物车商品数量
     * @return
     */
    @GetMapping("/getCartNum")
    public R getCartNum() {
        Long count = gameShoppingService.queryCartNum();
        return R.ok().setData(count);
    }

    /**
     * 添加购物车商品
     * @param gameCartReqVo
     * @return
     */
    @PostMapping("/addCart")
    public R addCart(@RequestBody GameCartReqVo gameCartReqVo) {
        gameShoppingService.saveCart(gameCartReqVo);
        return R.ok();
    }

    /**
     * 获取购物车商品列表
     * @return
     */
    @GetMapping("/getCartList")
    public R getCartList() {
        List<GameCartRespVo> list = gameShoppingService.querCartList();
        return R.ok().setData(list);
    }

    @DeleteMapping("/deleteCart/{gameId}")
    public R deleteCart(@PathVariable("gameId") Long gameId) {
        gameShoppingService.deleteCartInfo(gameId);
        return R.ok();
    }

    @PostMapping("/removeCart")
    public R removeCart(@RequestBody CartRemoveReqVo cartRemoveReqVo) {
        log.info("----进入方法----");
        gameShoppingService.removeCartByMemberId(cartRemoveReqVo);
        return R.ok();
    }

    /**
     * 添加心愿单
     * @param memberWishReqVo
     * @return
     */
    @PostMapping("/addWish")
    public R addWish(@RequestBody MemberWishReqVo memberWishReqVo) {
        gameShoppingService.addWishInCartPage(memberWishReqVo);
        return R.ok();
    }

}
